// https://www.youtube.com/watch?v=W6NZfCO5SIk&t=208s&ab_channel=ProgrammingwithMosh

// 使用 VSCode，并安装 Live Server 插件。

//------------------------------------------------------------
// This is my first JavaScript code.
console.log('Hello World');


//------------------------------------------------------------
// Variables

// 不建议使用 var 来声明变量
let name = 'Mosh';
console.log(name);

let firstName = 'Aster';
let lastName = 'Jian';

let fullName = `${firstName} ${lastName}`;
console.log(fullName);


//------------------------------------------------------------
// Constants

const interestRate = 0.3;
// interestRate = 1; 
console.log(interestRate);


//------------------------------------------------------------
// Primitive Types

// String
let name2 = 'Aster';
// Number
let age = 30;
// Boolean
let isApproved = true;
// Null(object)
let selectedColor = null;


//------------------------------------------------------------
// Dynamic Typing

// typeof(name) = string
console.log('typeof(name) =', typeof(name));

name = 1
// typeof(name) = number
console.log('typeof(name) =', typeof(name));

// typeof(selectedColor) = object
console.log('typeof(selectedColor) =', typeof(selectedColor));


//------------------------------------------------------------
// Objects

let person = {
    name: 'Mosh',
    age: 30,
};

// 使用点表示法
person.name = 'Aster';
console.log(person);

// 使用括号表示法
person['name'] = 'Mosh';

console.log(person.name);


//------------------------------------------------------------
// Arrays

let selectedColors = ['red', 'blue'];
console.log(selectedColors);

selectedColors[2] = 'green';
console.log(selectedColors[0]);
console.log(selectedColors[2]);

selectedColors[selectedColors.length] = 'dark';
console.log(selectedColors.length);


//------------------------------------------------------------
// Functions

function greet(firstName, lastName='') {
    console.log(`Hello ${firstName} ${lastName}!`);
}

greet('Aster', "Jian");
greet('Mosh');

function square(number) {
    return number * number;
}

let number = square(3);
console.log(number);
